package com.electronic.modules.electronicSealSignature.result;

import com.alibaba.fastjson.JSON;
import com.electronic.domain.CebsSdkProperties;
import com.electronic.jwt.JwtProperties;
import com.electronic.valid.BeanValidator;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @Author: IFCA
 * @Description: 二维码唯一标识
 */
@Data
public class QrCodeScanDTO {

    /**
     * 二维码唯一标识
     */
    @NotBlank(message = "二维码唯一标识不能为空")
    private String tid;

    /**
     * 二维码唯一标识
     */
    @Valid
    private JwtProperties jwtProperties;

    @NotNull(message = "初始化信息不能为空")
    private CebsSdkProperties cebsSdkProperties;

    public static QrCodeScanDTO validate(String businessData) {
        QrCodeScanDTO dto = JSON.parseObject(businessData, QrCodeScanDTO.class);
        //验证必填项
        BeanValidator.validateReturnException(dto);
        BeanValidator.validateReturnException(dto.getJwtProperties());
        return dto;
    }
}
